package com.batata.continuing.pojo.base;

import com.batata.continuing.config.HttpStatus;
import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;
import lombok.NonNull;

@ApiModel(value = "返回说明")
@Data
public class ResultData<T> {

    @ApiModelProperty(value = "成功标识；true：成功；false:失败")
    private boolean success;

    @ApiModelProperty(value = "返回状态码；200:成功")
    private int code;

    @ApiModelProperty(value = "描述信息")
    private String message;

    @ApiModelProperty(value = "数据包")
    private T data;

    public ResultData(boolean success, int code, String message, T data) {
        this.success = success;
        this.code = code;
        this.message = message;
        this.data = data;
    }

    public ResultData() {

    }

    public static ResultData<?> success() {
        return ResultData.success("操作成功");
    }


    public static ResultData<?> success(String message) {
        return ResultData.success(message, null);
    }

    public static ResultData<?> success(Object data) {
        return success(true, HttpStatus.SUCCESS, "请求成功", data);
    }

    public static ResultData<?> success(String message, Object data) {
        return success(true, HttpStatus.SUCCESS, message, data);
    }

    public static ResultData<?> success(int code, String message, Object data) {
        return success(true, code, message, data);
    }

    public static ResultData<?> success(boolean success, int code, String message, Object data) {
        return new ResultData<>(success, code, message, data);
    }


    /**
     * 返回错误消息
     *
     * @return 错误消息
     */
    public static ResultData<?> error() {
        return ResultData.error("操作失败");
    }

    /**
     * 返回错误消息
     *
     * @param msg 返回内容
     * @return 错误消息
     */
    public static ResultData<?> error(String msg) {
        return ResultData.error(msg, null);
    }

    /**
     * 返回错误消息
     *
     * @param msg  返回内容
     * @param data 数据对象
     * @return 错误消息
     */
    public static ResultData<?> error(String msg, Object data) {
        return new ResultData<>(false, HttpStatus.ERROR, msg, data);
    }

    public static ResultData<?> error(int code, String msg, Object data) {
        return new ResultData<>(false, code, msg, data);
    }


}
